﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GioiThieuDAO
/// </summary>
public class GioiThieuDAO
{
    DataProvider provider;
    public GioiThieuDAO()
	{
        provider = new DataProvider();
	}

    public List<GioiThieu> HienThiGioiThieu()
    {
        List<GioiThieu> list = new List<GioiThieu>();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_HienThi", provider.Conn);
            cmd.Parameters.Add("@TenBang", SqlDbType.VarChar).Value = "GioiThieu";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);
            provider.Conn.Close();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                GioiThieu dto = new GioiThieu();
                dto.NoiDung = ds.Tables[0].Rows[i]["NoiDung"].ToString();
                list.Add(dto);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return list;
    }

    public int CapNhatGioiThieu(string noiDung)
    {
        int kq = 0;
        try
        {
            SqlCommand cmd = new SqlCommand("sp_CapNhatGioiThieu", provider.Conn);
            cmd.Parameters.Add("@NoiDung", SqlDbType.NText).Value = noiDung;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            kq = 1;
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return kq;
    }
}